home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 February: Tool Chest / Dev.CD Feb 00 TC.toast / pc / tool chest / development kits / hypercard related / xcmds & xfcns / byrne's xcmds&xfcns / source / filefrompath.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-29  |  2.9 KB  |  128 lines

  1. /*
  2.     FileFromPath() XFCN v1.2
  3.     
  4.     ©1991 Apple Computer, Inc.; by Mike Byrne
  5.     
  6.     This XFCN will take a full pathname and simply return the filename at the end of it.
  7.     
  8.     Form:
  9.     FileFromPath(<pathName>)
  10.     
  11.     # the MPW 3.2 build commands:
  12.     C -b FileFromPath.c -mbg off
  13.         Link -w -t STAK -c WILD -rt XFCN=612 ∂
  14.             -m ENTRYPOINT ∂
  15.             -sg FileFromPath ∂
  16.             FileFromPath.c.o ∂
  17.             "{Libraries}HyperXLib.o" ∂
  18.             "{Libraries}Runtime.o" ∂
  19.             "{Libraries}Interface.o" ∂
  20.             "{CLibraries}StdCLib.o" ∂
  21.             -o "teststack"
  22. */
  23.  
  24. #include <string.h>
  25. #include <Memory.h>
  26. #include "HyperXCmd.h"
  27.  
  28. #define NULL (long) 0
  29. #define NIL (long) 0
  30.  
  31. #define kNumParams 1
  32.  
  33.  
  34. /* prototypes */
  35. void ErrorBack(XCmdPtr paramPtr, char *message);
  36. void MoveLockParams ( XCmdPtr paramPtr, short paramCount );
  37. void UnlockParams  ( XCmdPtr paramPtr, short paramCount );
  38.  
  39.  
  40.  
  41. pascal void EntryPoint(XCmdPtr paramPtr)
  42. {
  43.     /* variable declarations */
  44.     char*    fileName;
  45.  
  46.  
  47.     /* move high and lock the parameters. */
  48.     MoveLockParams(paramPtr, paramPtr->paramCount);
  49.  
  50.     /* check for copyright or syntax help request */
  51.     if (!strcmp( (char*)*paramPtr->params[0], "!") ) {
  52.         ErrorBack(paramPtr, "v1.2, ©1991 Apple Computer, Inc.; by Mike Byrne");
  53.         UnlockParams(paramPtr, paramPtr->paramCount);
  54.         return;
  55.     } else if (!strcmp ( (char*)*paramPtr->params[0], "?") ) {
  56.         ErrorBack(paramPtr, "FileFromPath syntax is 'FileFromPath(<pathName>)'");
  57.         UnlockParams(paramPtr, paramPtr->paramCount);
  58.         return;
  59.     }
  60.  
  61.     /* not a copyright or help request.       */     
  62.     /* check for correct number of parameters */
  63.     if (paramPtr->paramCount != kNumParams) {
  64.         ErrorBack(paramPtr, "Error: FileFromPath syntax is 'FileFromPath(<pathName>)'");
  65.         UnlockParams(paramPtr, paramPtr->paramCount);
  66.         return;
  67.     }
  68.     
  69.     /* do a strrchr to find the last colon, then increment by 1 to skip that. */
  70.     fileName =  strrchr ((char*) *paramPtr->params[0], ':');
  71.     fileName++;
  72.     
  73.     /* that's it.  go home. */
  74.     ErrorBack(paramPtr, fileName);
  75.     UnlockParams(paramPtr, paramPtr->paramCount);
  76.     return;
  77.  
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
  84.     
  85. /* allocate and load up paramPtr->returnValue with a string 
  86.    -------------------------------------------------------- */
  87. void ErrorBack(XCmdPtr paramPtr, char *message)
  88. {
  89.     Handle  mesHnd;
  90.  
  91.     /*
  92.         Allocate space for an error message.
  93.         Copy the string into it.
  94.         Return the handle to HyperCard.
  95.     */
  96.     mesHnd = NewHandle((long)(strlen(message)+1));
  97.     if (mesHnd == nil) return;
  98.     strcpy((char *)*mesHnd,message);
  99.     paramPtr->returnValue = mesHnd;
  100. }
  101.  
  102.  
  103.  
  104. /*  move high and lock down all parameters  
  105.     ----------------------------------------------------------------------- */
  106. void MoveLockParams ( XCmdPtr paramPtr, short paramCount )
  107. {
  108.     short i;
  109.     
  110.     for(i=0; i <= paramCount-1; i++)
  111.     {
  112.         MoveHHi(paramPtr->params[i]);
  113.         HLock(paramPtr->params[i]);
  114.     }
  115. }
  116.  
  117.  
  118.  
  119.  
  120. /* unlock all parameter handles in the XCmdBlock  
  121.    ---------------------------------------------  */
  122. void UnlockParams  ( XCmdPtr paramPtr, short paramCount )
  123. {    short i;
  124.     
  125.     for(i=0; i <= paramCount-1; i++)
  126.         { HUnlock(paramPtr->params[i]);}
  127. }
  128.